package com.googlecode.latvian_ebooks.glossary;

import java.util.{ List => JavaList }

/**
 * This class is parsing Leibniz's Monadology dictionary; could be used for
 * other dictionaries as well. You can run it with two commandline arguments -
 * first is glossary (plaintext file, where each line is separated with
 * semicolons); Second argument is the source text itself (where each fragment
 * e.g. stanza or paragraph, is written on a separate line)
 * 
 * The GlossaryMain prints out a report, where it enumerates the terms, lists
 * where they can be found, and prints some warning information, if the glossary
 * does not match the source document.
 */
object GlossaryMain {

  def main(args: Array[String]): Unit = {
    val gTerms = new GlossaryTerms(args(0));
    //    gTerms.parse(args(0));

    //    gTerms.findDuplicates

    val terms: List[FullTerm] = gTerms.getTerms();

    //    var count: Int = 0
    //    for (term <- terms) {
    //      count = count + 1
    //      val occurences: List[Int] = FileSearchUtility
    //        .findOccurences(term.pickTerm());
    //      val oldOccurences: List[Int] = FileSearchUtility
    //        .getLocationFragments(term.getLocations());

    // heuristics for finding missing entries
    //      if (term.getOtherLocations() == null || term.getOtherLocations().isEmpty()) {
    //        val knownLocations: List[Int] = FileSearchUtility.getLocationFragments(term.getLocations());
    //        val allOccurences: List[Int] = FileSearchUtility.findOccurences(term.pickTerm());
    //        // first = existing, but not found
    //        val first: List[Int] = allOccurences filterNot (knownLocations contains)
    //        if (!first.isEmpty) {
    //          term.setNotes(first.foldLeft("")((a, b) => a + "+" + b));
    //        }
    //
    //      }

    //      val second: List[Int] = oldOccurences filterNot (occurences contains)
    //      if (!second.isEmpty) {
    //        println("Could not find term " + term + " in " + oldOccurences)
    //      }

    //      println("" + count + "\t" + term + "\t" + occurences)
    //    }

    println("====================================================")

    val out = new java.io.FileWriter("data/words.xml")
    out.write(gTerms.toString)
    out.close()
    //println(gTerms.toString())
  }

}
